#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;

int n, m;
int st[N][2], re[N];
struct node { int v, f[2], ne[2]; } e[N];

void solve()
{
    while (cin >> n >> m) {
        for (int i = 1;i <= n;i++) {
            st[i][0] = st[i][1] = e[i].v = i;
            re[i] = e[i].f[0] = e[i].f[1] = 0;
            e[i].ne[0] = e[i].ne[1] = -1;
        }

        while (m--) {
            int a, b;cin >> a >> b;
            if (st[a][re[a]] != -1 && st[b][re[b]] != -1) {
                re[a] ^= 1;re[b] ^= 1;
                int ast = st[a][re[a]], aed = st[a][re[a] ^ 1];
                int bst = st[b][re[b]], bed = st[b][re[b] ^ 1];

                e[bed].ne[re[b]] = ast;
                e[ast].ne[re[a] ^ 1] = bed;

                if (re[a] ^ re[b]) {
                    e[ast].f[re[b]] ^= 1;
                    e[bed].f[re[a] ^ 1] ^= 1;
                }

                st[a][re[a]] = bst;
                st[b][0] = st[b][1] = -1;
            } else if (st[a][re[a]] == -1 && st[b][re[b]] != -1) {
                st[a][0] = st[b][0];
                st[a][1] = st[b][1];
                re[a] = re[b] ^= 1;

                st[b][0] = st[b][1] = -1;
            } else if (st[a][re[a]] != -1 && st[b][re[b]] == -1) {
                re[a] ^= 1;
            }

            int p = re[1];
            vector<int> ans;
            for (int it = st[1][re[1]];it != -1;it = e[it].ne[p]) {
                cout << e[it].v << ' ';
                p ^= e[it].f[p];
            }
            cout << '\n';
        }

        int p = re[1], len = 0;
        vector<int> ans;
        for (int it = st[1][re[1]];it != -1;it = e[it].ne[p]) {
            ans.push_back(e[it].v);
            len++;
            p ^= e[it].f[p];
        }

        cout << len << ' ';
        for (int it : ans) cout << it << ' ';
        cout << '\n';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}